
* producing Table A2, summary statistics based on ever districted status

clear all

cd "$datadir" 
 
use "fipspl_2000_demographics.dta"

gen placefips=600000+ fipspl

merge 1:1 placefips using "CA_all_districted_cities_2008_2020_w_placefips_for_merge_sept2024.dta"
drop if _merge==2
drop _merge

merge 1:1 fipspl using  "is contained in CEDA_ethnicity_vote_fips_08_15_17_v13.dta"
keep if _merge==3
drop _merge

gen never= first_D_year==. & always_D_new!=1
gen cat=.
replace cat=0 if never==1
replace cat=2 if always_D==1
replace cat=1 if first_D_year!=.
tab cat

label define cat 0 "Never Dist." 1 "Switch to Dist." 2 "Always Dist."
label values cat cat

merge 1:1 placefips using "more placefips demos.dta", gen(_merge_more)
drop if _merge_more==2


gen c_totalpop_1k=c_totalpop/1000
label variable c_totalpop_1k "Total Pop. (1000s)"
label variable c_share_pop_over18 "Share Over 18"
label variable c_share_pop_over65 "Share Over 18"
label variable c_share_pop_over65 "Share Over 65"
label variable c_share_renter_occ_housing "Share Renter Occ. Housing"
label variable c_share_ratio_inc_pov_7 "Share Inc > 2x Pov."
label variable c_share_cvap_aapi "Share AAPI (CVAP)"
label variable c_share_cvap_black "Share Black (CVAP)"
label variable c_share_cvap_white "Share White (CVAP)"
label variable c_share_cvap_hisp "Share AAPI (CVAP)"
label variable c_share_cvap_hisp "Share Hisp. (CVAP)"
label variable c_share_cvap_other "Share Other Race/Eth. (CVAP)"
label variable c_tp_demshare "Two-party Dem. Pres. Share (2016)"

label variable cat "Districted during Sample Period?"

dtable    c_totalpop_1k c_share_pop_over18 c_share_pop_over65 c_share_renter_occ_housing c_share_ratio_inc_pov_7 c_share_cvap_aapi c_share_cvap_black c_share_cvap_white c_share_cvap_hisp   if c_cvap_total!=. & c_totalpop<1000000, by(cat,   nototal)   nformat(%9.2f) export("$dist_output/susmtats2.tex", replace tableonly) 

